#include <iostream>
#include <algorithm>

using namespace std;

struct Data
{
    int id;
    int a;
    int b;
    int c;
    int sum;
};

bool compare(const Data& a, const Data& b)
{
    if (a.sum != b.sum)
    {
        return a.sum > b.sum;
    }
    if (a.a != b.a)
    {
        return a.a > b.a;
    }
    return a.id < b.id;
}

int main(int argc, char const *argv[])
{
    Data *arr;
    int n, i;
    cin >> n;
    arr = new Data[n];
    for (i = 0; i < n; i++)
    {
        cin >> arr[i].a >> arr[i].b >> arr[i].c;
        arr[i].sum = arr[i].a + arr[i].b + arr[i].c;
        arr[i].id = i + 1;
    }
    
    sort(arr, arr + n, compare);

    for (i = 0; i < min(n, 5); i++)
    {
        cout << arr[i].id << " " << arr[i].sum << "\n"; 
    }

    return 0;
}

